<?php
declare(strict_types=1);

namespace App\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Controller;
use App\Middleware\WebApiMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use Service\MnActivityService\ActivityService;
use Hyperf\Di\Annotation\Inject;

/**
 * 活动专区
 * @author huj
 * @Controller(prefix="/webapi/v1/activity")
 * @Middleware(WebApiMiddleware::class)
 */
class ActivityController extends AbstractController 
{
    /**
     * 通过 `@Inject` 注解注入由 `@var` 注解声明的属性类型对象
     * @Inject()
     * @var ActivityService
     */
    protected $activityService;

    /**
     * 获取活动列表
     * @RequestMapping(path="getActivityList", methods="get,post")
     */
    public function getActivityList(RequestInterface $request)
    {
        // $param = $request->getAttribute('param');
        $param        = $request->inputs(['mn_sid','page','limit','status','search','type','cid','mnid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->activityService->getActivityList($param);
    }

    /**
     * 新增活动
     * @RequestMapping(path="addActivity", methods="get,post")
     */
    public function addActivity(RequestInterface $request)
    {
        $param        = $request->inputs(['mn_sid','name','startdate','enddate','type','goods','full','drop','cid','mnid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->activityService->addActivity($param);
    }

    /**
     * 更改活动状态
     * @RequestMapping(path="changeStatus", methods="get,post")
     */
    public function changeStatus(RequestInterface $request)
    {
        $param        = $request->inputs(['activity_id','status']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->activityService->changeStatus($param);
    }

    /**
     * 获取活动商品
     * @RequestMapping(path="getActivityGoods", methods="get,post")
     */
    public function getActivityGoods(RequestInterface $request) {
        $param        = $request->inputs(['activity_id','page','limit']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->activityService->getActivityGoods($param);
    }

    /**
     * 修改活动
     * @RequestMapping(path="editActivity", methods="get,post")
     */
    public function editActivity(RequestInterface $request)
    {
        $param        = $request->inputs(['mn_sid','name','startdate','enddate','type','goods','activity_id','full','drop','status']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->activityService->editActivity($param);
    }

    /**
     * 列表
     * @RequestMapping(path="activityList", methods="get,post")
     */
    public function activityList(RequestInterface $request)
    {
        $param        = $request->inputs(['mn_sid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->activityService->seckillList($param);
    }

    /**
     * 场次内容
     * @RequestMapping(path="item", methods="get,post")
     */
    public function item(RequestInterface $request)
    {
        $param        = $request->inputs(['seckill_id', 'page', 'limit','mn_sid','is_admin']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->activityService->seckillItem($param);
    }

    /**
     * 商品促销详情
     * @RequestMapping(path="getActivityDetail", methods="get,post")
     */
    public function getActivityDetail(RequestInterface $request)
    {
        $param        = $request->inputs(['activity_id','mn_sid','mnid','cid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->activityService->getFormatDetail($param);
    }
}